//
//  ViewController.m
//  UI02_UILable_UITextField_UIImageView_UIButton
//
//  Created by aaaaaa on 16/6/6.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "ViewController.h"
#import "CustomUILable.h"
#import "CustomerUITextField.h"
#import "CustomerUIButton.h"

@interface ViewController ()<UITextFieldDelegate>

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self createUILable];
    [self createUITextField];
    [self createUIButton];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}



#pragma mark - UILable
- (void)createUILable{
    
    //UILable的创建
    /*UILabel *userNameLable = [[UILabel alloc] initWithFrame:CGRectMake(30, 50, 100, 40)];
    userNameLable.text = @"用户名";
    userNameLable.backgroundColor = [UIColor yellowColor];
    [self.view addSubview:userNameLable];
    [userNameLable release];*/
    
    //创建一个继承于UILable的子类，在子类中设置各种属性详见CustomUILable.h和.m文件
    CustomUILable *customUserNameLable = [[CustomUILable alloc] initWithFrame:CGRectMake(30, 50, 100, 40)];
    [self.view addSubview:customUserNameLable];
    [customUserNameLable release];
    
    //创建密码Lable
    CustomUILable *customPassWordLable = [[CustomUILable alloc] initWithFrame:CGRectMake(30, 120, 100, 80) withText:@"密码sdgfertretyryuy7iuqrwdetredgert"];
    [self.view addSubview:customPassWordLable];
    [customPassWordLable release];
}

#pragma mark - UITextField
- (void)createUITextField{
    
    CustomerUITextField *userNameTextField = [[CustomerUITextField alloc] initWithFrame:CGRectMake(150, 50, 200, 40)];
    [self.view addSubview:userNameTextField];
    [userNameTextField release];
    
    //通常情况下指定controller为代理人
    userNameTextField.delegate = self;
    
//    NSLog(@"%p", userNameTextField);
}

//点击return按键 触发下面的代理方法
- (BOOL)textFieldShouldReturn:(UITextField *)textField{
    //参数textFeild和userTextField指向同一块内存空间，二者相同
//    NSLog(@"%p", textField);
    //撤销第一响应者
    //resignFirstResponder是UIResponder的方法
    [textField resignFirstResponder];
    return YES;
}

//编辑状态的方法
- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField{
    NSLog(@"%d, %s", __LINE__, __FUNCTION__);
    return YES;
}

- (void)textFieldDidBeginEditing:(UITextField *)textField{
    NSLog(@"%d, %s", __LINE__, __FUNCTION__);
}

- (BOOL)textFieldShouldEndEditing:(UITextField *)textField{
    NSLog(@"%d, %s", __LINE__, __FUNCTION__);
    return YES;
}

- (void)textFieldDidEndEditing:(UITextField *)textField_{
    NSLog(@"%d, %s", __LINE__, __FUNCTION__);
}




#pragma mark - UIButton
- (void)createUIButton{
    //创建UIButton的子类CustomerUIButton 详见CustomerUIButton.h和.m文件
    CustomerUIButton *login = [CustomerUIButton buttonWithType:UIButtonTypeSystem withFrame:CGRectMake(50, 400, 100, 40)];
//    login.backgroundColor = [UIColor redColor];
    [self.view addSubview:login];
    
    /****重点****/
    /*
     *target 是指让谁来执行action方法 一般赋值self 让controller来执行
     *action 自定义方法名
     * controlEvents 在那种控制事件下执行方法<#(UIControlEvents)#>
     *addTarget:self action:<#(nonnull SEL)#>forControlEvents:
     */
    
    [login addTarget:self action:@selector(loginAction:) forControlEvents:UIControlEventTouchUpInside];
    NSLog(@"%p", login);
    
}

- (void)loginAction:(CustomerUIButton *)button{
    NSLog(@"%p", button);
    NSLog(@"已经登录");
}
















































@end
